<script setup>
import { onMounted, ref, watch } from 'vue'
import { useRouter, useRoute } from 'vue-router'
const router = useRouter()
const route = useRoute()
const lists = ref([])
// 生命周期-页面一/加载/进入/刷新/触发，组件切换不触发
/*onMounted(() => {
  // console.log(route)
  console.log(route.matched)
  lists.value = route.matched
})*/

// 页面初次进入不触发，需要另外开启immediate，只监听组件路由数据变化，跟页面加不加载无关，新旧值
watch(route, (to, form) => {
  lists.value = to.matched // 重新赋值
}, {
  // 页面初始化也监听，启动页面加载就开始监听
  immediate: true
})
</script>

<template>
  <!--面包屑-->
  <div class="breadcrumb">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item v-for="item in lists" :key="item.path"><!--{{item.name}}-->{{item.meta.title}}</el-breadcrumb-item>
    </el-breadcrumb>
  </div>
</template>

<style lang="scss" scoped>
.breadcrumb{
  padding: 0 20px;
  background-color: #fff;
  height: 25px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ebeef5;
}
</style>